<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Crypt;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $req)
    {
        // put()存session
        // $req->session()->put('key1','赵四');
        // $rs = $req->session()->get('key1');
        // var_dump($rs);

        // echo "<hr>";

        // pull()取出session并删除
        // $rs1 = $req->session()->pull('key1','default');
        // var_dump($rs1);

        // push()可以将新的值加入到数组中
        // $req->session()->push('key2','刘能');
        // $req->session()->push('key3','宋晓峰');

        //forget()删除一条session,flush()清空session
        // $req->session()->forget('key1');
        // $req->session()->flush();

        // all(),获取所有session
        // $rs = $req->session()->all();
        // print_r($rs);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //passs bcrypt
        //encrypt 加密数据 key值 aes-256
        $pas = Crypt::encrypt('123456'); //1.
        echo $pas;
        echo '<hr>';
        echo $pasb = bcrypt('123456'); //2.
        echo '<hr>';
        echo md5('123456');  //3.
        echo '<hr>';
        echo sha1('123456');  //4.
        echo '<hr>';
        echo md5(sha1('123456')); //5.
        echo '<hr>';
        echo sha1(md5('123456')); //6.
        echo '<hr>';

        // decrypt 解密 
        echo Crypt::decrypt($pas);
        echo '<hr>';

        //hash加密
        $rs = Hash::make('123456');
        echo $rs;
        echo '<hr>';
        //用check方法可以验证一个hash密码
        if(Hash::check('123456',$rs)) {
            echo '密码正确';
        } else {
            echo "密码错误!!!";
        }
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
